<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});


/**
 * 数据可视化
 */
Route::group(['prefix' => 'admin', 'namespace' => 'Api'], function () {
    //收银系统---本周销售额统计
    Route::get('week_sale', 'EchartController@week_sale')->name('week_sale');

    //商城系统---会员性别及人数统计  http://inventory.dev/api/admin/sex_total
    Route::get('sex_total', 'EchartController@sex_total')->name('sex_total');

    //商城系统---会员省份及人数统计
    Route::get('province_total', 'EchartController@province_total')->name('province_total');

    //商城系统---支付方式统计
    Route::get('pay_type', 'EchartController@pay_type')->name('pay_type');

});

/***
 * 商城前端--微信自动回复消息
 */
Route::group(['prefix' => 'admin', 'namespace' => 'Wechat'], function () {

    Route::any('/wechat', 'WechatController@serve');

});


/***
 * vue.js前端路由（使用vue.js实现前后端分离）
 * 1. 首先进入后端项目安装cors跨域请求包，参考laravel精选大全。
 * 2. 参考vue.js文档，任意目录新建项目。启动项目之前安装接口地址请求包axios，命令：npm install axios --save
 * 3. 了解vue.js语法实际开发项目，路由--模板布局--引用组件--通过接口地址获取后端的数据赋值后发给模板渲染
 * 4. 购物车做接口认证，实现步骤如下：
 *    1.laravel精选大全搜索 jwt ，对照文档安装即可。
 *    2.参考资料：http://laravelacademy.org/post/3640.html
 */
Route::group(['namespace' => 'Api'], function () {

    Route::get('/', 'HomeController@index');

    Route::group(['prefix' => 'good'], function () {
        //商品分类
        Route::get('tag', 'GoodController@tag');

        //商品详情
        Route::get('{id}', 'GoodController@show');

        //商品列表
        Route::get('/', 'GoodController@index');
    });


    //购物车,以下路由写法是路由新版写法
//    Route::group(['prefix' => 'cart', ['middleware' => 'client.credentials']], function () {
    Route::middleware('client.credentials')->prefix('cart')->group(function () { //此处只能使用5.6的路由写法，无法解释
        Route::post('/', 'CartController@store');
        Route::get('/', 'CartController@index');
        Route::patch('change_num', 'CartController@change_num');
        Route::delete('/{id}', 'CartController@destroy');
    });

    //订单
    Route::middleware('client.credentials')->prefix('order')->group(function () {
        //下单
        $this->get('checkout', 'OrderController@checkout');

        //生成订单,支付
        $this->post('/', 'OrderController@store');
        $this->get('pay/{id}', 'OrderController@pay');

        //删除订单
        $this->delete('{id}', 'OrderController@destroy');

        //服务--我的订单
        $this->get('{id}', 'OrderController@show');

        //服务--全部订单
        $this->get('/', 'OrderController@index');
    });

    //地址管理
    Route::middleware('client.credentials')->prefix('address')->group(function () {
        //改变默认地址
        $this->patch('/', 'AddressController@default_address');
    });

    $this->resource('address', 'AddressController')->except('create', 'show')->middleware('client.credentials');

    //服务
    Route::prefix('customer')->group(function () {
        $this->get('/', 'CustomerController@service');
    });

});
